function addCommas(num: number | string): string {
  // 将数字转为字符串
  let str = num.toString();
  // 判断是否存在小数点
  const decimalIndex = str.indexOf('.');
  let decimalPart = '';
  if (decimalIndex !== -1) {
    decimalPart = str.slice(decimalIndex);
    str = str.slice(0, decimalIndex);
  }
  // 正则表达式添加千分分隔符
  const reg = /(\d{1,3})(?=(\d{3})+(?:$|\.))/g;
  str = str.replace(reg, '$1,');
  return str + decimalPart;
}
export default addCommas;
